package middleware

/*
 * @Desc: 服务器内部错误
 * @author: bsyz
 * @version: v1.0.0
 */

import (
	"github.com/PhlexTheCharr/GoFurry-framework/common"
	"github.com/gin-gonic/gin"
	"runtime/debug"
)

func Recover() gin.HandlerFunc {
	return func(context *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				if gin.IsDebugging() {
					debug.PrintStack()
				}
				common.NewResponse(context).Error("服务器内部错误")
			}
		}()
		context.Next()
	}
}
